# include <cstdio>
# include <algorithm>
# define MAXN 45023
using namespace std;

int f[MAXN], n, m, *a = new int();

int main() { 
    freopen("diet.in", "r", stdin);
    freopen("diet.out", "w", stdout);
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; i++) { 
        scanf("%d", a);
        for(int j = n; j >= *a; j--) { 
            f[j] = max(f[j], f[j - *a] + *a);
        }
    }
    printf("%d\n", f[n]);
}
